﻿using System.Web;
using Microsoft.Practices.Unity;

namespace Cos.Core.Module.Unity.Lifetime
{
    public class PerRequestLifetimeManager : LifetimeManager
    {
        public PerRequestLifetimeManager(string key)
        {
            this.Key = key;
        }

        public string Key { get; private set; }

        public override object GetValue()
        {
            return HttpContext.Current.Items[Key];
        }

        public override void SetValue(object newValue)
        {
            HttpContext.Current.Items[Key] = newValue;
        }

        public override void RemoveValue() { } // this does not appear to be used ...
    }
}